/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package maquinaVirtual.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author H
 */
public class ManipuladorDeArquivo {
    
    private File arquivo;
    private FileReader reader;
    private BufferedReader readerLine;
    
    public ManipuladorDeArquivo( File arquivo ){
        
        this.arquivo = arquivo;
        try {
            this.reader = new FileReader(arquivo);
            this.readerLine = new BufferedReader(reader);
            
        } catch (FileNotFoundException ex) {
            
            Logger.getLogger(ManipuladorDeArquivo.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public String getLinha(){
        
        try{
            //System.out.println(this.readerLine.readLine());
            return this.readerLine.readLine();
        }
        catch(IOException ex){
            Logger.getLogger(ManipuladorDeArquivo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return null;

    }

        public void testaGetLinha(){
        
        try{
            while(true)
                System.out.println(this.readerLine.readLine());
            //return this.readerLine.readLine();
        }
        catch(IOException ex){
            Logger.getLogger(ManipuladorDeArquivo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //return null;

    }
    
    public void fechaRecursos(){
        try {
            
            this.readerLine.close();
            this.reader.close();
            
        } catch (IOException ex) {
            Logger.getLogger(ManipuladorDeArquivo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
}
